#pragma once 

class PathNode {
public:
	PathNode() {
		for (int i = 0; i < N_NEIGH; ++i)
			neigh[i] = nullptr;
	}

	static const int N_NEIGH = 8;

	float f;
	float g;
	PathNode* backPtr;
	PathNode* neigh[N_NEIGH];
	glm::vec2 pos;
	bool walkable;
};

class pathingGroup;

class PathingManager {

public:
	static PathingManager* getInstance();

	void Move(std::vector<PlayerObj*> movers, const glm::vec2 & targetLoc);
	void update(float dt);
	void draw(const glm::mat4 & viewMatrix);
	
private:
	static PathingManager* instance;
	PathingManager();
	void reset();
	
	std::vector<PathNode*> FindShortestPath(PathNode* startNode, PathNode* targetNode);

	std::vector<PathNode*> pathMap;
	glm::ivec2 nodeDim;
	float nodeSize;

	std::vector<pathingGroup> pathingGroupList;
};

class pathingGroup {

	struct Pather {

		Pather(PlayerObj* mover) : 
			finished(false), mover(mover), pathIndex(-1)
		{}

		PlayerObj* mover;
		int pathIndex;
		bool finished;
	};

public:
	pathingGroup(const std::vector<PathNode*> & path, const std::vector<PlayerObj*> & movers);
		

	void update(float dt);

	bool finished;
	std::vector<Pather*> pathers;
	int attractorIndex;
	std::vector<PathNode*> path;
private:
	
	//glm::vec2 attractorPos;
};